#ifndef GROUND_H
#define GROUND_H
#include "mainwindow.h"

struct ColorStop { int pos; QColor color; };

const std::array<ColorStop, 5> kStops = {{
    {  0, QColor("#2B8CFF") },
    { 25, QColor("#26C5FF") },
    { 50, QColor("#4AE37D") },
    { 75, QColor("#FFDE70") },
    {100, QColor("#FF4B4B") }
}};

class particle;
class ground : public QWidget
{
    Q_OBJECT
public:
    ground();
    void initParticle();
    float Density(float radio, float dis);
    void getgradient(bool& comfort);
    void traverseGrid(float h, float winW, float winH);//网格法
    float GetDistance(QPointF p1, QPointF p2);
    float GetDensity(QPointF tar, QPointF my);
    float GetDensityX(QPointF tar, QPointF my, float Step);
    float GetDensityY(QPointF tar, QPointF my, float Step);
    bool collisionTarget(QPointF p1, QPointF p2, float r);
    QPointF createIntrinsicPressure(particle* part, QPointF p, QPointF mouse, float Radio);//场
    float IntrinsicPressurePower(float radio, float dis);
    void moveAlongConveyor(particle* part, float height, float power);//传送带
    QColor speedToGradientColor(int value);
    qreal mapRange(qreal value,
                   qreal inMin,  qreal inMax,
                   qreal outMin, qreal outMax,
                   bool  clamp = true);
protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
private slots:
    void onUpdate();
private:
    QTimer *timer;
    QList<particle*>particleList;
    float DensityRadio = 5;
    float mass = 1.f;
    float visMu   = 400.f;   // 黏性常数
    float xsphEta = 5.f;  // XSPH
    bool leftClick = false;
    QPointF MousePos;
    float mousePower = 1.f;
};

#endif // GROUND_H
